package com.xw.userService.dto;


import java.io.Serializable;


import com.xw.userService.enums.ResultCodeEnum;


/**
 * < 基础响应 >
 * 
 * 包含常规请求响应的参数
 * 
 */
public class ResultDto<T> implements Serializable {

	private static final long serialVersionUID = 5598379493227689413L;

	/**
	 * result : 响应码
	 */
	private String code;

	/**
	 * description ： 响应描述
	 */
	private String message;

	/**
	 * data : 结果数据
	 */
	private T object;

	public ResultDto() {

	}

	public ResultDto(T object) {
		this.object = object;
	}

	public ResultDto(ResultCodeEnum.System source) {
		this.code = source.getCode();
		this.message = source.getMsg();
	}

	public ResultDto(ResultCodeEnum.System source, T object) {
		this.code = source.getCode();
		this.message = source.getMsg();
		this.object = object;
	}


	public static ResultDto<?> result(ResultCodeEnum.System source) {
		ResultDto<?> result = new ResultDto<Object>();
		result.setCode(source.getCode());
		result.setMessage(source.getMsg());
		return result;
	}

	public static ResultDto<?> result(ResultCodeEnum.System source, Object data) {
		ResultDto<?> result = new ResultDto<Object>(data);
		result.setCode(source.getCode());
		result.setMessage(source.getMsg());
		return result;
	}

	public static ResultDto<?> result(ResultCodeEnum.System source, String message, Object data) {
		ResultDto<?> result = new ResultDto<Object>(data);
		result.setCode(source.getCode());
		result.setMessage(message);
		return result;
	}


	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public T getObject() {
		return object;
	}

	public void setObject(T object) {
		this.object = object;
	}

	@Override
	public String toString() {
		return "ResultDto [code=" + code + ", message=" + message + ", object=" + object + "]";
	}


	
}
